#!/bin/bash
#
# Cydonia - DynDNS Client
# http://cydonia.googlecode.com
# Franklin Ronald - McFox Software Design
# fronald@mcfox.com.br
#

ME=$0

if [ ! -f $ME ]; then
    ME=`which $0`
fi

if [ ! -f $ME ]; then
    echo "Unable to find myself in the file system!"
    exit 1
fi

if [ "$2" ]
then
   echo "Pass just one parameter!" 
   exit 1
fi

if [ -e /tmp/Cydonia.jar ]; then rm -f /tmp/Cydonia.jar; fi

cat $ME | sed '0,/[B]EGIN_CYDLIB/d' | uudecode -o /tmp/Cydonia.jar

if [ "$1" = "--stop" ]
then
   PID=`cat /tmp/cydonia.pid`
   kill -9 $PID
   echo "Cydonia is stopped."
   rm -f /tmp/cydonia.pid
   exit 0
fi

if [ "$1" = "--start" ]
then
   if [ -e /tmp/cydonia.pid ];
      then
         echo "Another instance of Cydonia is already running."
         exit 1
      else
	  java -jar /tmp/Cydonia.jar "$@" & echo $! > /tmp/cydonia.pid
   fi
else
   java -jar /tmp/Cydonia.jar "$@"
fi

exit

# BEGIN_CYDLIB
